#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define maxn 10000

typedef struct Stack_{
    int data[maxn];
    int cnt;  // how many values in data
}array_stack;

array_stack *init_arraystack(){
    array_stack *as = (array_stack *)malloc(sizeof(array_stack));
    memset(as, 0, sizeof(array_stack));
    printf("Initializing! stack.cnt: %d \n", as->cnt);
    return as;
}

void push_arraystack(array_stack *as, int value){
    if (as != 0){
        as->data[as->cnt] = value;
        as->cnt++;
    }else{
        printf("Stack is None! \n");
    }
}

int pop_arraystack(array_stack *as){
    int popped;
    if (as != 0 && as->cnt != 0){
        as->cnt--;
        popped = as->data[as->cnt];
        return popped;
    }else{
        printf("Stack is None or Empty! \n");
    }
}

void show_arraystack(array_stack *as){
    if (as!=0 && as->cnt!=0){
        for (int i=as->cnt-1; i>=0; --i){
            printf("%d ", as->data[i]);
        }
        printf("\n");
    }else{
        printf("Stack is None or Empty! \n");
    }
}

int main(void){
    array_stack *as = init_arraystack();
    printf("Array_stack has been Initialized! \n");
    show_arraystack(as);
    int i;
    for (i=0; i<10; ++i){
        push_arraystack(as, i);
        show_arraystack(as);
    }
    printf("Array_stack has been Pushed 10 values! \n");

    int popped;
    for (i=0; i<10; ++i){
        popped = pop_arraystack(as);
        printf("Popped value: %d \n", popped);
        show_arraystack(as);
    }
    printf("Array_stack has been Popped 10 values! \n");
}